import request from "@/utils/request.js";

export const listSecondhandCategory = async () => {
    const res = await request.get('/secondhandCategory/list');
    return res.map(e => ({...e, value: e.id, label: e.name}))
}
export const listUser = async () => {
    const res = await request.get('/user/list');
    return res.map(e => ({...e, value: e.id, label: e.nickname}))
}

export const statusOptions = [
    {value: 1, label: '在售', type: 'primary'},
    {value: 2, label: '已售', type: 'info'},
]

export const fields = [
    {
        prop: 'image',
        label: '商品主图',
        type: 'image',
        width: 100,
    },
    {
        prop: 'categoryId',
        label: '所属分类',
        type: 'remote-select',
        api: listSecondhandCategory,
        width: 120,
    },
    {
        prop: 'sellerId',
        label: '所属卖家',
        type: 'remote-select',
        api: listUser,
        width: 120,
        requireRoles: ['admin']
    },
    {
        prop: 'name',
        label: '商品名称',
        type: 'longtext',
        search: true,
        width: 200,
    },
    {
        prop: 'images',
        label: '商品图片',
        type: 'image-list',
        width: 120,
    },
    {
        prop: 'description',
        label: '商品描述',
        type: 'longtext',
        width: '150',
    },
    {
        prop: 'price',
        label: '价格',
        type: 'number',
        width: 120,
    },
    {
        prop: 'contact',
        label: '联系方式',
        type: 'text',
        width: 170,
    },
    {
        prop: 'status',
        label: '是否在售',
        type: 'switch',
        options: statusOptions,
        search: true,
        width: 170,
    },
    {
        prop: 'createTime',
        label: '创建时间',
        type: 'datetime',
        formHidden: true,
        width: 190,
    },
    {
        prop: 'updateTime',
        label: '更新时间',
        type: 'datetime',
        formHidden: true,
        width: 190,
    }
]